﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Diagnostics;

namespace Compiled_Tests
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class StepDialog : Window, IStepper
    {
        
        public event StepEvent OnStep;

        public StepDialog()
        {
            InitializeComponent();
            StepButton.Content = "Start";
            SetForegroundWindow(Process.GetCurrentProcess().MainWindowHandle);
            StepButton.Focus(); 
            // to avoid null exception
            OnStep += delegate() { };
            SetForegroundWindow(Process.GetCurrentProcess().MainWindowHandle);
            StepButton.Focus(); 
        }

        private void StepButton_Click(object sender, RoutedEventArgs e)
        {
            StepButton.Content = "Running...";
            OnStep();
        }

        public void Run()
        {
 	        ShowDialog();
            Break();
        }

        [System.Runtime.InteropServices.DllImport("user32.dll")]
        private static extern bool SetForegroundWindow(IntPtr hWnd);



        public void Break()
        {
            StepButton.Content = "Step";
            SetForegroundWindow(Process.GetCurrentProcess().MainWindowHandle);
            StepButton.Focus(); 
        }

        public void Dispose()
        {
            Close();
        }
    }
}
